define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {

            //$(document).on('click', '.btn-callback', function () {
                //Layer.alert(JSON.stringify(Table.api.selecteddata(table)));
                //return false;
                //console.log($("input[name=callback]").val(),'jizi')
                //layer.alert($("input[name=callback]").val())
                //Fast.api.close($("input[name=callback]").val());
            //});

            // 初始化表格参数配置
            Table.api.init();

            //绑定事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                var panel = $($(this).attr("href"));
                if (panel.size() > 0) {
                    Controller.table[panel.attr("id")].call(this);
                    $(this).on('click', function (e) {
                        $($(this).attr("href")).find(".btn-refresh").trigger("click");
                    });
                }
                //移除绑定的事件
                $(this).unbind('shown.bs.tab');
            });

            //必须默认触发shown.bs.tab事件
            $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
        },
        table: {
            first: function () {
                // 表格1
                var table1 = $("#table1");
                table1.bootstrapTable({
                    url: '/admin/mall_goods_choose/table1',
                    toolbar: '#toolbar1',
                    sortName: 'id',
                    search: false,
                    columns: [
                        [
                            {field: 'state', checkbox: true, },
                            {field: 'id', title: 'ID'},
                            {field: 'name', title: __('Name'), operate: 'LIKE'},
                            {field: 'price', title: __('Price'), operate: 'LIKE'},
                            {field: 'stock', title: __('Stock'), operate: 'LIKE'},
                        ]
                    ]
                });

                $(document).on('click', '.btn-callback', function () {
                    Layer.alert(JSON.stringify(Table.api.selecteddata(table1)));
                    Fast.api.close('1+'+JSON.stringify(Table.api.selecteddata(table1)));
                });
                // 为表格1绑定事件
                Table.api.bindevent(table1);
            },
            second: function () {
                // 表格2
                var table2 = $("#table2");
                table2.bootstrapTable({
                    url: '/admin/mall_goods_choose/table2',
                    extend: {
                        index_url: '',
                        add_url: '',
                        edit_url: '',
                        del_url: '',
                        multi_url: '',
                        table: '',
                    },
                    toolbar: '#toolbar2',
                    sortName: 'id',
                    search: false,
                    columns: [
                        [
                            {field: 'state', checkbox: true, },
                            {field: 'id', title: 'ID'},
                            {field: 'name', title: __('Name'), operate: 'LIKE'},
                            {field: 'price', title: __('Price'), operate: 'LIKE'},
                        ]
                    ]
                });

                $(document).on('click', '.btn-callback', function () {
                    Layer.alert(JSON.stringify(Table.api.selecteddata(table2)));
                    Fast.api.close('2+'+JSON.stringify(Table.api.selecteddata(table2)));
                });

                // 为表格2绑定事件
                Table.api.bindevent(table2);
            },
            third: function () {
                // 表格2
                var table3 = $("#table3");
                table3.bootstrapTable({
                    url: '/admin/mall_goods_choose/table3',
                    extend: {
                        index_url: '',
                        add_url: '',
                        edit_url: '',
                        del_url: '',
                        multi_url: '',
                        table: '',
                    },
                    toolbar: '#toolbar3',
                    sortName: 'id',
                    search: false,
                    columns: [
                        [
                            {field: 'state', checkbox: true, },
                            {field: 'id', title: 'ID'},
                            {field: 'name', title: __('Name'), operate: 'LIKE'},
                            {field: 'pack_price', title: __('Pack_price'), operate: 'LIKE'},
                        ]
                    ]
                });

                $(document).on('click', '.btn-callback', function () {
                    Layer.alert(JSON.stringify(Table.api.selecteddata(table3)));
                    Fast.api.close('3+'+JSON.stringify(Table.api.selecteddata(table3)));
                });

                // 为表格2绑定事件
                Table.api.bindevent(table3);
            }
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
        }
    };
    return Controller;
});